<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="testpaperid" name="testpaperid" class="form-control" type="hidden"
                               th:value="${paperid}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">选择题库</label>
                            <div class="col-sm-8">
                                <select data-placeholder="选择用户" id="tikuid" name="tikuid"
                                        class="form-control chosen-select">
                                    <option th:each="Tiku:${list}" th:value="${Tiku.id}"
                                            th:text="${Tiku.tkname}" onchange=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">选择题</label>
                            <div class="col-sm-8">
                                <input id="puanduanid" name="puanduanid" class="form-control" type="text"
                                        readonly placeholder="点击选择" onclick="openpuanduan('1')">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">单选题</label>
                            <div class="col-sm-8">
                                <input id="danxuanid" name="danxuanid" class="form-control" type="text"
                                        readonly placeholder="点击选择" onclick="openpuanduan('2')">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">多选题</label>
                            <div class="col-sm-8">
                                <input id="duoxuanid" name="duoxuanid" class="form-control" type="text"
                                        readonly placeholder="点击选择" onclick="openpuanduan('3')">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script>
    function openpuanduan(type) {
        var id = $('#tikuid').val();
        layer.open({
            type: 2,
            title: '编辑',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['99%', '99%'],
            content: '/contract/testpapertimu/open?id=' + id + '&type=' + type
        });
    }

    $().ready(function () {
        validateRule();
    });

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });

    function save() {
        $.ajax({
            cache: true,
            type: "POST",
            url: "/contract/testpapertimu/save",
            data: $('#signupForm').serialize(),// 你的formid
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });

    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                name: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: icon + "请输入姓名"
                }
            }
        })
    }
</script>
</body>
</html>
